function AddRobotInGroupController(
    $rootScope,
    RobotGroup,
    Robot,
    API,
    $http,
    $uibModal,
    $scope,
    $state,
    $stateParams
){
    var vm=this;
    vm.isSelectting = false;
    vm.isshow = false;
    vm.isCommit = true;
    vm.queryParams = _.clone($stateParams);
    vm.resultMsg;
    vm.scope = $rootScope.$new();

    //已选择添加机器人数组容器
    vm.selectedArray = [];

    //是否显示机器人添加按钮
    vm.isShowAddBtn = true;


    vm.cancel = function() {
        $state.go('robotGroupDetail', {groupId: vm.queryParams.groupId});
    }

    vm.addToGroup = function($index){
        var keepGoing = false;

        vm.isShowAddBtn = false;
        //console.log("-------------------------------------------------------------------------------------------")
        //console.log("开始提交机器人======================index为"+$index+",编号为："+vm.items[$index].robotNumber);
        if($index>=0){
            //判断要添加的机器人是否已经添加，防止重复添加
            for(var i=0;i<vm.selectedArray.length;i++){
                //console.log("正在筛选=============，共筛选"+vm.selectedArray.length+"次");
                if(vm.selectedArray[i] == vm.items[$index].id){
                    console.log("1111111"+vm.items[$index].robotNumber);
                    vm.isCommit=false;
                    break;
                }
            }
            //console.log("筛选完毕=================================");
            if(vm.isCommit){
                //console.log("开始提交=================================");
                vm.selectedArray.push(vm.items[$index].id);
                RobotGroup.addRobotInGroup({robotId: vm.items[$index].id, groupId: vm.queryParams.groupId}).$promise.then(function(response){
                    var result = response.result;
                    if(result == 'success'){
                        //console.log("提交"+vm.items[$index].robotNumber+"成功=============");
                        vm.items.splice($index,1);
                    }else if(result == "err"){
                        vm.resultMsg = "添加失败,"+ response.msg +"！";
                        keepGoing = true;
                    }else{
                        vm.resultMsg = "添加失败！请稍后再试！";
                        keepGoing = true;
                    }
                    if(keepGoing){
                        vm.scope.data = {
                            msg:vm.resultMsg
                        }
                        var tipsModel = $uibModal.open({
                            templateUrl: 'tipsModel.html',
                            controller: 'robotGroupTipsCtrl',
                            scope:vm.scope
                        });
                    }
                    vm.isCommit = true;
                    vm.isShowAddBtn = true;
                })
            }
        }
        //if(vm.isCommit){
        //    vm.isCommit = false;
        //
        //}
        //console.log("-------------------------------------------------------------------------------------------")
    }


    vm.select = function (){
        vm.isSelectting = true;
        var selectAllRobotByRobotIdBtn = angular.element("#selectAllRobotByRobotIdBtn");
        selectAllRobotByRobotIdBtn.prop('disabled',true);

        Robot.selectAllByRobotNumber({
            robotNumber: vm.robotNumber,
            groupId:vm.queryParams.groupId,
            pageInfo: {
                pageSize: vm.queryParams.size,
                pageNumber: vm.queryParams.page
            }
        }).$promise.then(function(response){
            if(response.result == 'err'){
                vm.resultMsg = "查询失败：" + response.msg;
                vm.scope.data = {
                    msg:vm.resultMsg
                }
                var tipsModel = $uibModal.open({
                    templateUrl: 'tipsModel.html',
                    controller: 'robotGroupTipsCtrl',
                    scope:vm.scope
                });
            }else{
                selectAllRobotByRobotIdBtn.prop('disabled',false);
                var rusersesultObj = response.page;
                vm.items=rusersesultObj.content;
                vm.isLoaded = true;
                vm.totalItems = rusersesultObj.totalElements
                vm.totalPages = rusersesultObj.totalPages
                if(vm.items == 0){
                    vm.isshow = true;
                }else{
                    vm.isshow = false;
                }
            }
            vm.isSelectting = false;
        })
    }

    vm.select();
}